package com.weavernorth.action.purchase;

import net.sf.json.JSONObject;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;

public class PurchaseApproveJs {

    public static  JSONObject getNum(String sqr,String id,String strSqsj,String strFqgc) {
        BaseBean bb =new BaseBean();
        JSONObject jsonObject = new JSONObject();
        RecordSet rs =new RecordSet();
        RecordSet rsTwo =new RecordSet();
        RecordSet rsThree =new RecordSet();

        //申请时间月
        String  strMonth="";
        bb.writeLog("申请时间:"+strSqsj);
        if(strSqsj!=null&&!"".equals(strSqsj)){
            strMonth=strSqsj.split("-")[0]+"-"+strSqsj.split("-")[1];
        }
        //查询表单的名称
        String strSql="select tablename  from workflow_bill where id = (select formid from workflow_base where id=" + id + " and isbill=1)";
        bb.writeLog(strSql+"查询表单的名称的sql");
        rs.execute(strSql);
        //如果有值
        if(rs.next()){
            //取出表单名称
            String strTablename = rs.getString("tablename");
            bb.writeLog("表单名称"+strTablename);
            String strSqlTwo = "select count(t.sqr) as num from  " + strTablename + " t , workflow_requestbase wr  where t.requestid=wr.requestid and   wr.currentnodetype!=0  and t.cglx=1  and t.sqr= '" + sqr + "' and substr(t.sqsj,0,7)='"+strMonth+"' and t.fqgc='"+strFqgc+"'";
            bb.writeLog("查询自己提交加急的流程个数"+strSqlTwo);
            rsTwo.execute(strSqlTwo);
            //如果有值
            if(rsTwo.next()){
                jsonObject.put("num", Util.null2String(rsTwo.getString("num")));
            }
            //查询所有的加急流程的个数的sql
            String strSqlThree = "select count(t.cglx) as nums from  " + strTablename + " t , workflow_requestbase wr  where t.requestid=wr.requestid and   wr.currentnodetype!=0  and t.cglx=1 and t.sqr= '" + sqr + "' and t.fqgc='"+strFqgc+"'";
            rsThree.execute(strSqlThree);
            if(rsThree.next()){
                jsonObject.put("nums", Util.null2String(rsThree.getString("nums")));
            }
        }
        bb.writeLog("json:"+jsonObject);
        return jsonObject;
    }


}
